﻿using EFDemo.Chapte2.Models;
using Microsoft.EntityFrameworkCore;

namespace EFDemo.Chapte2
{
    public class StudyContext:DbContext
    {
        public StudyContext()
        {

        }

        public StudyContext(DbContextOptions<StudyContext> options):base(options)
        {

        }

        public DbSet<Teacher> Teachers { get; set; }

        public DbSet<Student> Students { get; set; }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            base.OnConfiguring(optionsBuilder);
            optionsBuilder.UseMySql("Server=127.0.0.1;Database=study;uid=root;pwd=123456;Charset=utf8mb4", ServerVersion.Parse("5.7"));
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);
            modelBuilder.ApplyConfigurationsFromAssembly(this.GetType().Assembly);
        }
    }
}
